(function($){
	function init(opts){
		document.domain = cookieDomain ; //'ailkcloud.com';
		var $cont=$('<div id="uploadPicWin_common"></div>');
		var $ifram=$('<iframe id="picIframe_common" name="picIframe_common" style="width:100%;height:100%;border:0px;" ></iframe>');
		var $btn=$('<input type="button" id="insertend_common" style="display:none;"/>');
		var $rsCont=$('<input id="insertUrls_common" type="text" style="display:none;"/>');
		$cont.append($ifram).append($btn).append($rsCont).appendTo('body');
//		$.data($("#insertend_common"),"picRoom",{options:opts});
		$("#insertend_common").data('picRoom',opts);
		$('#uploadPicWin_common').window({
			title:opts.title,
			width:opts.width,
			height:opts.height,
			minimizable: false,
			maximizable: false, 
			closable:true,
			closed: true,
			draggable:true,
			resizable:false,
			modal: true,
			shadow: false
		});
		$ifram.attr("src", opts.url);
		$btn.click(function(){
			var np=$("#insertend_common").data('picRoom');
			if(np.callback){
				try {
					var iJquery=window.picIframe_common.jQuery;  
					var $mydata=iJquery('#dataCont_pic');
					var urlMap=$mydata.data('urlMap');
					var urls=[];
					$.each(urlMap,function(k,v){
						if(opts.picSize != null){
							var indx=v.lastIndexOf(".");
							v=v.substring(0,indx)+'_'+opts.picSize+'.'+v.substring(indx+1,v.length);
						}
						urls.push(v);
					});
					setTimeout(np.callback(urls,urlMap),0);
					$("#uploadPicWin_common").window('close');
				} catch (e) {
				}
				
			}
		});
		opts.win=$cont;
	};
	function open(){
		$("#uploadPicWin_common").window('open');
	};
	function move(parm){
		$("#uploadPicWin_common").window('move',parm);
	}
	$.picRoomUtil=function(par,parm){
		if(typeof par=="string"){
			return $.picRoomUtil.methods[par](parm);
		}
		par=par||{};
		par=$.extend({},$.picRoomUtil.defaults,par);
		init(par);
	};
	$.picRoomUtil.methods={
		options:function(){
			return $("#insertend_common").data('picRoom');
		},
		open:function(){
			open();
		},move:function(parm){ 
			move(parm);
		}
	};
	$.picRoomUtil.defaults={picSize:null,url:mainDomain+'/upload/toPicUpload.action',title:'图片空间',width:900,height:500,callback:null};
})(jQuery);
